package cn.yj.netty.message.chain;

import io.netty.channel.ChannelHandlerContext;

/**
 * @author 永健
 * @since 2022-02-16 14:01
 */
public abstract class AbstractMessageChain<T> implements IMessageChain<T> {

    private AbstractMessageChain nextChain;
    private ChannelHandlerContext channelHandlerContext;

    protected String getHost(){
        return this.channelHandlerContext.channel().remoteAddress().toString();
    }

    @Override
    public void handler(ChannelHandlerContext channelHandlerContext, T msg) {
        this.channelHandlerContext=channelHandlerContext;
        doHandler(channelHandlerContext, msg);
    }

    abstract void doHandler(ChannelHandlerContext channelHandlerContext, T msg);

    public AbstractMessageChain setNextChain(AbstractMessageChain nextChain) {
        this.nextChain = nextChain;
        return this;
    }

    public AbstractMessageChain getNextChain() {
        return nextChain;
    }
}
